home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / Algorithms / insertion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-19  |  1.3 KB  |  49 lines

  1. #include<hold/anim.h>
  2.  
  3. /* 000 */ void insert_control(void);
  4. /* 001 */ void insertion(int [], int);
  5.  
  6. /* 002 */ void insert_control(void){
  7. /* 003 */ int d[10] =  {-1,10,9,8,7,6,5,4,3,2};
  8. /* 004 */ int parts = 10;
  9.  
  10.             a_func("insert_control",2);
  11.             a_irayini(d,"d",parts,3);
  12.             a_intini(parts,"parts",4);
  13.             a_show(5);
  14. /* 005 */   insertion(d, parts);
  15.             a_endfunc("insert_control",6);
  16. /* 006 */ }
  17.  
  18. /* 007 */ void insertion(int a[], int n){
  19. /* 008 */ int i,j,t;
  20.  
  21.             a_func("insertion",7);
  22.             a_iraypas("a",7);
  23.             a_intini(n,"n",7);
  24.             a_intini(i,"i",8);
  25.             a_intini(j,"j",8);
  26.             a_intini(t,"t",8);
  27.             a_intass("i","1",9);
  28.             a_intcomp("i < n",9);
  29.  
  30. /* 009 */   for(i=1;i<n;i++){
  31. /* 010 */     t = a[i];
  32.               a_intass("t","a[i]",10);
  33. /* 011 */     j = i;
  34.               a_intass("j","i",11);
  35.               a_intcomp("a[j-1] > t",12);
  36. /* 012 */     while(a[j-1]>t){
  37. /* 013 */       a[j] = a[j-1];
  38.                 a_intass("a[j]","a[j-1]",13);
  39. /* 014 */       j--;
  40.                 a_intass("j","j-1",14);
  41. /* 015 */     }
  42. /* 016 */     a[j]=t;
  43.               a_intass("a[j]","t",16);
  44.               a_intass("i","i+1",9);
  45.               a_intcomp("i<n",9);
  46. /* 017 */   }
  47.             a_endfunc("insertion",18);
  48. /* 018 */ }
  49.